<?php echo $this->validation->error_string; ?>
<?php echo form_open($this->curl . '/create/' . $id_tests, 'enctype="multipart/form-data" name="create_form" id="create_form"')?>
<input type="hidden" name="id_test" id="id_test" value="<?php echo $id_tests; ?>" />

<table class="nostyle forma" width="590" border="0" cellpadding="3" cellspacing="0" style="">
<tr>
	<th style="width: 250px"><?php $this->load->view('_elements/obligatory.php'); ?><?php echo $this->question_model->fields['question']?></th>
	<td><div class="textarea_80"><textarea name="question" id="question"><?php echo $this->validation->question; ?></textarea></div></td>
</tr>
<tr>
	<th><?php $this->load->view('_elements/obligatory');?><?php echo $this->question_model->fields['type']?></th>
	<td><div class="input_300"><?php echo form_dropdown('type', $this->question_model->type, array($this->validation->type), 'id="type" onchange="selectTestType(this)"', TRUE)?></div></td>
</tr>
<tr>
	<th><?php echo $this->question_model->fields['is_sample']?></th>
	<td><?php echo form_checkbox('is_sample', 1, ($this->input->post('is_sample')) ? TRUE : FALSE, 'class="checkbox"')?></td>
</tr>
<tr>
	<th><?php echo $this->question_model->fields['attachment']?></th>
	<td><?php echo form_upload('attachment', null, 'size="30"')?></td>
</tr>
<tr id="tr_new_option">
	<td colspan="2"><input onclick="addNewOption()" name="new_option" type="button" class="" id="new_option" value="<?php echo T_('New option')?>" /></td>
</tr>
<tr>
	<td colspan="2">&nbsp;</td>
</tr>
<tr>
	<td></td>
	<td>
		<input name="edit" type="submit" class="btn btn_save" id="submit" value="<?php echo T_('Submit')?>" />
		<input name="reset"  type="reset"  class="btn btn_clear" id="reset" value="<?php echo T_('Reset')?>" onclick="$('#create_form input[type=text]').val('');" />		
	</td>
</tr>
</table>

<?php echo form_close()?>

<script type="text/javascript">
var num_options = 1;

function selectTestType(obj)
{
	if ($(obj).val() == 2)
	{
		//$('#value').val('').addClass('disabled').attr('disabled', 'disabled');
	}
	else if ($(obj).val() == 1)
	{
		//$('#value').removeClass('disabled').removeAttr('disabled');
	}
}

function addNewOption()
{
	var type = $('#type').val();

	switch(type)
	{
		case '4':
			if (num_options > 2)
			{
				alert('<?php echo T_("You are not allowed to add more options fot this question type."); ?>');
				return;
			}
			break;
	}

	num_options += 1;
	
	$('<tr><td colspan="2"><fieldset><legend><a href="javascript:void(0)" title="Delete" class="btn_del_option" id="opt_"><img src="/img/close.png" width="16" height="16" /></a>Option</legend><table class="nostyle forma">'+
		'<tr>'+
			'<th style="width: 230px">Answer</th>'+
			'<td><div class="input_300"><input type="text" name="option[]" value="" class="input-text" /></div></td>'+
		'</tr>'+
		'<tr>'+
			'<th>Is correct?</th>'+
			'<td><input type="checkbox" name="is_correct[]" value="" class="is_correct" /><input type="hidden" value="" name="id_option[]" /></td>'+
		'</tr>'+
	  '</table></fieldset></td></tr>').insertAfter("#tr_new_option");

	$('.btn_del_option').unbind().click(function(){
		deleteOption($(this));
	})

	$('.is_correct').unbind().click(function(){
		if ($(this).attr('checked'))
		{
			$(this).next('input').val('1');
		}
		else
		{
			$(this).next('input').val('0');
		}
	})
}

function deleteOption(obj)
{
	$(obj).parent().parent().parent().parent().remove();
	num_options -= 1;
}

$(document).ready(function(){
	$('.btn_del_option').unbind().click(function(){
		deleteOption($(this));
	})
});
</script>